﻿    function InitAccountAll(){
           
        datamodel.init();
        
        var asset = datamodel.getTotalAssets();
       var debt = datamodel.getTotalDebts();
       var realasset = asset + debt;
       $("#assetaccount").html(asset);
       $("#debtaccount").html(-debt);
        $("#realassetaccount").html(realasset);
        
        $("#accountlistaccount").html("");
        var index = 0;
        for(var key in datamodel.accounts)
        {
            var account = datamodel.accounts[key];
            var accounthtml = "<li class=\"list{2}\" data-value=\"{3}\"> <a href=\"javascript:;\">" + 
                                " <div class=\"left\"><span class=\"accoutname\">{0}</span></div>" +
                                " <div class=\"right\"> <span class=\"money\">￥{1}</span><span class=\"arrow\"></span></div></a> </li>"
                                            
            accounthtml = accounthtml.format(account.name,account.money,(index) % 4 + 1,account.id);
            $("#accountlistaccount").append(accounthtml);
             
             ++ index;
            
        }
        
       
       
        
   
    }
    

     function addAccount()
     {
        $('#addAccountContent').slideToggle('normal');
        
         var money = $("#addAccountMoney").val();
         var name = $("#addAccountName").val();
         
         var newAccount = new Account(0,name,money);
         newAccount.Add();
         
         $("#addAccountMoney").val("0");
         $("#addAccountName").val("");
         InitAccountAll();
         
         

    }